package com.gmaf.mas.launch.property;

import java.io.File;
import com.gmaf.mas.launch.FilePathUtils;

public class Property implements Executor
{
	private String name = null;
	private String value = null;
	private String location = null;
	
	public Property()
	{
		
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getValue()
	{
		return value;
	}

	public void setValue(String value)
	{
		this.value = value;
	}

	public String getLocation()
	{
		return location;
	}

	public void setLocation(String location)
	{
		this.location = location;
	}
	
	public void execute(PropertyParser parser, Configuration config)
	{
		if(name == null)
		{
			return;
		}
		
		String parsedName = parser.parseProperty(name, config);
		String str = null;
		if(location != null)
		{
			str = parser.parseProperty(location, config);
			File file = new File(str);
			if(!file.isAbsolute())
			{
				str = config.getProperty("basedir") + File.separator + str;
			}
			str = FilePathUtils.getCanonicalPath(str);
		}
		else if(value != null)
		{
			str = parser.parseProperty(value, config);
		}
		
		if(str != null)
		{
			config.setProperty(parsedName, str);
		}
	}
}
